# -*- coding: utf-8 -*-
"""
------------------------------------------------------------------------------
    File Name:  formula_plt
    Author   :  wanwei1029
    Date     :  2018/12/6
    Desc     :
------------------------------------------------------------------------------
"""
import matplotlib.pyplot as plt
import numpy as np
import math


def plt_formula():
    doc_count = 1000000
    x = np.linspace(0, 100, 100)
    # y = 1 +(doc_count-x+0.5)/(x+0.5)
    y = list()
    for idx in x:
        y1 = 1 + (doc_count-idx+0.5)/(idx+0.5)
        y_inx = math.log10(y1)
        y.append(y_inx)
    print(y)
    plt.plot(x, y)
    plt.show()


def plt_formula_2():
    x = np.arange(1, 11)
    # 注意，这里用range不行。
    k1 = 1.2
    b = 0.75
    # fieldLength = 9
    tf = 1
    avgFieldLength = 7.5
    # y = (x * (k1 + 1)) / (x + k1 * (1 - b + b * fieldLength / avgFieldLength))
    y = (tf * (k1 + 1)) / (tf + k1 * (1 - b + b * x / avgFieldLength))
    plt.xlabel("fieldLength")
    plt.ylabel("tfNorm(i)")
    l1, = plt.plot(x, y)
    # k1 = 0.3
    b = 0.1
    # y1 = (x * (k1 + 1)) / (x + k1 * (1 - b + b * fieldLength / avgFieldLength))
    y1 = (tf * (k1 + 1)) / (tf + k1 * (1 - b + b * x / avgFieldLength))
    l2, = plt.plot(x, y1,
             color='red',  # 线条的颜色
             linewidth=1.0,  # 线条的粗细
             linestyle='--'  # 线条的样式
             )
    # plt.legend([l1, l2], ['k1 = 1.2', 'k1 = 0.3'], loc='upper left')
    plt.legend([l1, l2], ['b = 0.75', 'b = 0.1'], loc='best')
    # loc 表示位置
    # 'best': 0, (only implemented for axes legends)(自适应方式)
    # 'upper right': 1,
    # 'upper left': 2,
    # 'lower left': 3,
    # 'lower right': 4,
    # 'right': 5,
    # 'center left': 6,
    # 'center right': 7,
    # 'lower center': 8,
    # 'upper center': 9,
    # 'center': 10,
    plt.show()


def demo():
    """
    """
    plt_formula_2()


if __name__ == '__main__':
    test_method = "demo"
    if test_method == "demo":
        demo()
